<?php
/**
 * @file random.php
 * @package V2
 * @subpackage 
 * @version $id: 0.1 UTF-8 2009-8-16 下午01:46:48 $
 * @author LD King (mifunny.info)
 * @copyright Copyright (c) 2007 - 2009 MiFunny China Inc. (http://mifunny.info)
 * 随机跳转到某一网页
 */
$timeStart = microtime(true);

$link = mysql_connect('localhost:3306', 'root', 'shadow');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
//echo 'Connected successfully';
if (!mysql_select_db('7heart', $link)) {
	die('Could not select database: '.mysql_error());
}

//$sql = "SELECT `ID` , `post_name` FROM `wp_posts` WHERE `post_type` = 'post' ORDER BY rand( ) LIMIT 1 ";
$query = "SELECT `ID` , `post_name` FROM `wp_posts` AS t1
		JOIN (	SELECT round( rand( ) * ( SELECT max( `ID` ) FROM `wp_posts` ) ) AS sid
			) AS t2 
			WHERE t1.id >= t2.sid AND `post_type` = 'post' 
			ORDER BY t1.id LIMIT 1 ";
			
$result = mysql_query($query, $link);
if (!$result) {
    die('DB Error, could not query the database： '.mysql_error());
}
$row = mysql_fetch_assoc($result);
$url = "http://localhost/7heart/item/".$row['ID'].'-'.$row['post_name'].'/';
//var_dump($row);
mysql_free_result($result);
mysql_close($link);
$timeEnd = microtime(true);
$timeTotal = $timeEnd - $timeStart;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>随便逛逛 | 七心导购网_7heart.com</title>
<meta name="robots" content="index,follow" />
<meta name="keywords" content="网上购物 导购 淘宝购物 数码 手机 MP3 MP4 女装 女士精品 男装 流行男鞋 女鞋 箱包皮具 运动鞋 运动服 运动配件 流行首饰 时尚饰品 女士内衣 男士内衣 家居服 居家日用 厨房餐饮 卫浴洗浴 彩妆 美容护肤 童装 母婴用品 食品 茶叶 零食 特产" />
<meta name="description" content="在淘宝购物，先来七心导购网找最物美价廉的宝贝！" />
<meta http-equiv="refresh" content="2;url=<?php echo $url; ?>">
<style type="text/css" >
html, body, div, span,applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dd, dl, dt, li, ol, ul, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {margin:0;padding:0;}
html,body{background:#fff}
body{font:normal normal normal 14px/1.5em Simsun,Arial, "Arial Unicode MS", Mingliu, Helvetica; color:#616161;text-align: center;height:100%;word-break : break-all;}
div {text-align:left;}
a {text-decoration:none;color:#1d6ac9;}
a:hover {text-decoration:underline; }
li {list-style-type:none;}
img {border-style: none;}
p {margin-bottom:20px;line-height:24px; }
</style>
</head>
<body>

<div style="width:700px;height:300px;margin:0 auto;background:#eee;padding:20px 10px 0;">
	<p>亲爱的朋友,您好:</p>
	<p style="text-indent:2em;">系统将于 3秒 之后自动跳转到随机页面。 如果没有跳转，猛击
		<strong style="color:#1d6ac9;"><a href="<?php echo $url; ?>" title="" target="'_self'">这里</a></strong></p>
	<p>页面跳转倒计时(<b><span style="color:#ec5105;" id="timer">3</span></b>)</p>
	<p style="margin-top:50px;text-align:right;">七心楼 淘大大 [<a href="http://www.7heart.com/" title="七心导购网" target="'_self'">www.7heart.com</a>]</p>
</div>
            <script type="text/javascript">
			(function(){
			var i=3;
            setInterval(function(){
				document.getElementById('timer').innerHTML=i;
				if(i > 0){
					i--;
				}
			},1000);
			})();
            </script>
<!-- Use: <?php echo $timeTotal; ?> s. -->

</body>
</html>